//
//  RecommendScrollView.m
//  Travel
//
//  Created by 王嘉倩 on 15/9/18.
//  Copyright (c) 2015年 TeamThree. All rights reserved.
//

#import "RecommendScrollView.h"

@implementation RecommendScrollView

- (instancetype)initWithFrame:(CGRect)frame imageArr:(NSMutableArray *)imageArr delegate:(id)delegate action:(SEL)action timer:(NSTimeInterval)timer selector:(SEL)selector {
    self = [super initWithFrame:frame];
    if (self) {
        
        // 创建一个放轮播图的数组
        NSMutableArray *insertArr = [NSMutableArray arrayWithArray:imageArr];
        // 将imageArr的第一张图插到insertArr的最后一张
        [insertArr insertObject:imageArr[0] atIndex:imageArr.count];
        
        // 将imageArr的最后一张插入的insertArr的第一张
        [insertArr insertObject:imageArr[imageArr.count - 1] atIndex:0];
        
        // 设置scrollView的属性
        self.contentSize = CGSizeMake(kWidth * insertArr.count, 0);
        self.pagingEnabled = YES;
        self.bounces = YES;
        self.showsHorizontalScrollIndicator = NO;
        self.contentOffset = CGPointMake(kWidth, 0);
        self.delegate = delegate;
        for (int i = 0; i < insertArr.count; i++) {
            TapimageView *tapView = [[TapimageView alloc] initWithFrame:(CGRectMake(kWidth * i, 0, kWidth, self.bounds.size.height)) target:delegate action:action];
            tapView.image = [UIImage imageNamed:insertArr[i]];
            [self addSubview:tapView];
            [tapView release];
        }
        
        [NSTimer scheduledTimerWithTimeInterval:timer target:delegate selector:selector userInfo:nil repeats:YES];
    }
    return self;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
